﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kovan.DAL.Config;
using Kovan.Model.Entity.Config;
using Kovan.Model.Parameter.Config;
using System.IO;
using Kovan.Library.IO;

namespace Kovan.BLL.Config
{
    public class BPicGroup
    {
        DPicGroup dal = new DPicGroup();

        #region 当前类的实例
        private static readonly BPicGroup Instances = new BPicGroup();

        private BPicGroup() { }

        public static BPicGroup GetInstances()
        {
            return Instances;
        }
        #endregion

        /// <summary>
        /// 获取列表数据
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public IEnumerable<tb_picgroup> GetList(PPicGroup param)
        {
            return dal.GetList(param);
        }

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public tb_picgroup GetModel(long id)
        {
            return dal.GetModel(id);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(tb_picgroup model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(long id)
        {
            return dal.Delete(id);
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(tb_picgroup model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public int BatchDelete(IEnumerable<string> ids)
        {
            string ukeys = string.Empty;
            var result = dal.BatchDelete(ids, out ukeys);
            if (!string.IsNullOrEmpty(ukeys))
            {
                var attr = ukeys.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (attr != null && attr.Length > 0)
                {
                    foreach (var item in attr)
                    {
                        var path = PathUtility.GetPhysicalPath(string.Format("~/content/Uploads/pic/{0}/", item));
                        DirectoryInfo di = new DirectoryInfo(path);
                        if (di.Exists)
                        {
                            di.Delete(true);
                        }
                    }
                }
            }
            return result;
        }
    }
}
